'use strict';

//数据初始化
$(function () {

    inform();
})

//增加
function add() {
    location.href = './AorE.html';
}
//编辑
function update() {
    location.href = './AorE.html';
}
//返回
function cancel() {
    location.href = './index.html';
}

//数据
function inform(datas) {
    $.get(`http://localhost:3000/blog`, data => {
        if (datas) {
            data = datas
        }
        $('.row').remove();
        data.forEach(item => {
            let html = `
            <tr class="row" key="${item.id}">
                <td>${item.biaoti}</td>
                <td>${item.zhaiyao}</td>
                <td>${item.neirong}</td>
                <td>${item.fenlei}</td>
                <td>${item.zuozhe}</td>
                <td>${item.fabiaoshijian}</td>
                <td>
                <input type="button" value="编辑" onclick="update(${item.id})">
                <input type="button" value="删除" onclick="deleted(${item.id})">
                </td>
            </tr>
            `
            $('#tb').append(html);
        })
    })
}


//查询
function query() {
    let keyword = $('#keyword').val();
    console.log(keyword);
    $.get(`http://localhost:3000/blog?keyword=${keyword}`, data => {
        inform(data);
    })
}